home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / docs / gdb / gdb.i1 (.txt) next >
GNU Info File  |  1994-07-26  |  50KB  |  970 lines

  1. This is Info file ./gdb.info, produced by Makeinfo-1.52 from the input
  2. file gdb.texinfo.
  3. START-INFO-DIR-ENTRY
  4. * Gdb::                         The GNU debugger.
  5. END-INFO-DIR-ENTRY
  6.    This file documents the GNU debugger GDB.
  7.    This is Edition 4.12, January 1994, of `Debugging with GDB: the GNU
  8. Source-Level Debugger' for GDB Version 4.12.
  9.    Copyright (C) 1988, '89, '90, '91, '92, '93 Free Software
  10. Foundation, Inc.
  11.    Permission is granted to make and distribute verbatim copies of this
  12. manual provided the copyright notice and this permission notice are
  13. preserved on all copies.
  14.    Permission is granted to copy and distribute modified versions of
  15. this manual under the conditions for verbatim copying, provided also
  16. that the entire resulting derived work is distributed under the terms
  17. of a permission notice identical to this one.
  18.    Permission is granted to copy and distribute translations of this
  19. manual into another language, under the above conditions for modified
  20. versions.
  21. File: gdb.info,  Node: Top,  Next: Summary,  Prev: (DIR),  Up: (DIR)
  22. Debugging with GDB
  23. ******************
  24.    This file describes GDB, the GNU symbolic debugger.
  25.    This is Edition 4.12, January 1994, for GDB Version 4.12.
  26. * Menu:
  27. * Summary::                     Summary of GDB
  28. * New Features::                New features since GDB version 3.5
  29. * Sample Session::              A sample GDB session
  30. * Invocation::                  Getting in and out of GDB
  31. * Commands::                    GDB commands
  32. * Running::                     Running programs under GDB
  33. * Stopping::                    Stopping and continuing
  34. * Stack::                       Examining the stack
  35. * Source::                      Examining source files
  36. * Data::                        Examining data
  37. * Languages::                   Using GDB with different languages
  38. * Symbols::                     Examining the symbol table
  39. * Altering::                    Altering execution
  40. * GDB Files::                   GDB files
  41. * Targets::                     Specifying a debugging target
  42. * Controlling GDB::             Controlling GDB
  43. * Sequences::                   Canned sequences of commands
  44. * Emacs::                       Using GDB under GNU Emacs
  45. * GDB Bugs::                    Reporting bugs in GDB
  46. * Command Line Editing::        Facilities of the readline library
  47. * Using History Interactively::
  48. * Renamed Commands::
  49. * Formatting Documentation::    How to format and print GDB documentation
  50. * Installing GDB::              Installing GDB
  51. * Index::                       Index
  52. File: gdb.info,  Node: Summary,  Next: New Features,  Prev: Top,  Up: Top
  53. Summary of GDB
  54. **************
  55.    The purpose of a debugger such as GDB is to allow you to see what is
  56. going on "inside" another program while it executes--or what another
  57. program was doing at the moment it crashed.
  58.    GDB can do four main kinds of things (plus other things in support of
  59. these) to help you catch bugs in the act:
  60.    * Start your program, specifying anything that might affect its
  61.      behavior.
  62.    * Make your program stop on specified conditions.
  63.    * Examine what has happened, when your program has stopped.
  64.    * Change things in your program, so you can experiment with
  65.      correcting the effects of one bug and go on to learn about another.
  66.    You can use GDB to debug programs written in C or C++.  For more
  67. information, see *Note C and C++: C.
  68.    Support for Modula-2 and Chill is partial.  For information on
  69. Modula-2, see *Note Modula-2: Modula-2.  There is no further
  70. documentation on Chill yet.
  71.    Debugging Pascal programs which use sets, subranges, file variables,
  72. or nested functions does not currently work.  GDB does not support
  73. entering expressions, printing values, or similar features using Pascal
  74. syntax.  GDB can be used to debug programs written in Fortran, although
  75. it does not yet support entering expressions, printing values, or
  76. similar features using Fortran syntax.  It may be necessary to refer to
  77. some variables with a trailing underscore.
  78. * Menu:
  79. * Free Software::               Freely redistributable software
  80. * Contributors::                Contributors to GDB
  81. File: gdb.info,  Node: Free Software,  Next: Contributors,  Up: Summary
  82. Free software
  83. =============
  84.    GDB is "free software", protected by the GNU General Public License
  85. (GPL).  The GPL gives you the freedom to copy or adapt a licensed
  86. program--but every person getting a copy also gets with it the freedom
  87. to modify that copy (which means that they must get access to the
  88. source code), and the freedom to distribute further copies.  Typical
  89. software companies use copyrights to limit your freedoms; the Free
  90. Software Foundation uses the GPL to preserve these freedoms.
  91.    Fundamentally, the General Public License is a license which says
  92. that you have these freedoms and that you cannot take these freedoms
  93. away from anyone else.
  94. File: gdb.info,  Node: Contributors,  Prev: Free Software,  Up: Summary
  95. Contributors to GDB
  96. ===================
  97.    Richard Stallman was the original author of GDB, and of many other
  98. GNU programs.  Many others have contributed to its development.  This
  99. section attempts to credit major contributors.  One of the virtues of
  100. free software is that everyone is free to contribute to it; with
  101. regret, we cannot actually acknowledge everyone here.  The file
  102. `ChangeLog' in the GDB distribution approximates a blow-by-blow account.
  103.    Changes much prior to version 2.0 are lost in the mists of time.
  104.      *Plea:* Additions to this section are particularly welcome.  If you
  105.      or your friends (or enemies, to be evenhanded) have been unfairly
  106.      omitted from this list, we would like to add your names!
  107.    So that they may not regard their long labor as thankless, we
  108. particularly thank those who shepherded GDB through major releases: Fred
  109. Fish (releases 4.12, 4.11, 4.10, 4.9), Stu Grossman and John Gilmore
  110. (releases 4.8, 4.7, 4.6, 4.5, 4.4), John Gilmore (releases 4.3, 4.2,
  111. 4.1, 4.0, and 3.9); Jim Kingdon (releases 3.5, 3.4, 3.3); and Randy
  112. Smith (releases 3.2, 3.1, 3.0).  As major maintainer of GDB for some
  113. period, each contributed significantly to the structure, stability, and
  114. capabilities of the entire debugger.
  115.    Richard Stallman, assisted at various times by Peter TerMaat, Chris
  116. Hanson, and Richard Mlynarik, handled releases through 2.8.
  117.    Michael Tiemann is the author of most of the GNU C++ support in GDB,
  118. with significant additional contributions from Per Bothner.  James
  119. Clark wrote the GNU C++ demangler.  Early work on C++ was by Peter
  120. TerMaat (who also did much general update work leading to release 3.0).
  121.    GDB 4 uses the BFD subroutine library to examine multiple
  122. object-file formats; BFD was a joint project of David V.
  123. Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
  124.    David Johnson wrote the original COFF support; Pace Willison did the
  125. original support for encapsulated COFF.
  126.    Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
  127. Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
  128. support.  Jean-Daniel Fekete contributed Sun 386i support.  Chris
  129. Hanson improved the HP9000 support.  Noboyuki Hikichi and Tomoyuki
  130. Hasei contributed Sony/News OS 3 support.  David Johnson contributed
  131. Encore Umax support.  Jyrki Kuoppala contributed Altos 3068 support.
  132. Keith Packard contributed NS32K support.  Doug Rabson contributed Acorn
  133. Risc Machine support.  Chris Smith contributed Convex support (and
  134. Fortran debugging).  Jonathan Stone contributed Pyramid support.
  135. Michael Tiemann contributed SPARC support.  Tim Tucker contributed
  136. support for the Gould NP1 and Gould Powernode.  Pace Willison
  137. contributed Intel 386 support.  Jay Vosburgh contributed Symmetry
  138. support.
  139.    Rich Schaefer and Peter Schauer helped with support of SunOS shared
  140. libraries.
  141.    Jay Fenlason and Roland McGrath ensured that GDB and GAS agree about
  142. several machine instruction sets.
  143.    Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped
  144. develop remote debugging.  Intel Corporation and Wind River Systems
  145. contributed remote debugging modules for their products.
  146.    Brian Fox is the author of the readline libraries providing
  147. command-line editing and command history.
  148.    Andrew Beers of SUNY Buffalo wrote the language-switching code, the
  149. Modula-2 support, and contributed the Languages chapter of this manual.
  150.    Fred Fish wrote most of the support for Unix System Vr4.  He also
  151. enhanced the command-completion support to cover C++ overloaded symbols.
  152.    Hitachi America, Ltd. sponsored the support for Hitachi
  153. microprocessors.
  154. File: gdb.info,  Node: New Features,  Next: Sample Session,  Prev: Summary,  Up: Top
  155. New Features since GDB Version 3.5
  156. **********************************
  157. *Targets*
  158.      Using the new command `target', you can select at runtime whether
  159.      you are debugging local files, local processes, standalone systems
  160.      over a serial port, or realtime systems over a TCP/IP connection.
  161.      The command `load' can download programs into a remote system.
  162.      Serial stubs are available for Motorola 680x0, Intel 80386, and
  163.      Sparc remote systems; GDB also supports debugging realtime
  164.      processes running under VxWorks, using SunRPC Remote Procedure
  165.      Calls over TCP/IP to talk to a debugger stub on the target system.
  166.      Internally, GDB now uses a function vector to mediate access to
  167.      different targets; if you need to add your own support for a
  168.      remote protocol, this makes it much easier.
  169. *Watchpoints*
  170.      GDB now sports watchpoints as well as breakpoints.  You can use a
  171.      watchpoint to stop execution whenever the value of an expression
  172.      changes, without having to predict a particular place in your
  173.      program where this may happen.
  174. *Wide Output*
  175.      Commands that issue wide output now insert newlines at places
  176.      designed to make the output more readable.
  177. *Object Code Formats*
  178.      GDB uses a new library called the Binary File Descriptor (BFD)
  179.      Library to permit it to switch dynamically, without
  180.      reconfiguration or recompilation, between different object-file
  181.      formats.  Formats currently supported are COFF, ELF, a.out, Intel
  182.      960 b.out, MIPS ECOFF, HPPA SOM (with stabs debugging), and
  183.      S-records; files may be read as .o files, archive libraries, or
  184.      core dumps.  BFD is available as a subroutine library so that
  185.      other programs may take advantage of it, and the other GNU binary
  186.      utilities are being converted to use it.
  187. *Configuration and Ports*
  188.      Compile-time configuration (to select a particular architecture and
  189.      operating system) is much easier.  The script `configure' now
  190.      allows you to configure GDB as either a native debugger or a
  191.      cross-debugger. *Note Installing GDB::, for details on how to
  192.      configure.
  193. *Interaction*
  194.      The user interface to the GDB control variables is simpler, and is
  195.      consolidated in two commands, `set' and `show'.  Output lines are
  196.      now broken at readable places, rather than overflowing onto the
  197.      next line.  You can suppress output of machine-level addresses,
  198.      displaying only source language information.
  199. *C++*
  200.      GDB now supports C++ multiple inheritance (if used with a GCC
  201.      version 2 compiler), and also has limited support for C++ exception
  202.      handling, with the commands `catch' and `info catch': GDB can
  203.      break when an exception is raised, before the stack is peeled back
  204.      to the exception handler's context.
  205. *Modula-2*
  206.      GDB now has preliminary support for the GNU Modula-2 compiler,
  207.      currently under development at the State University of New York at
  208.      Buffalo.  Coordinated development of both GDB and the GNU Modula-2
  209.      compiler will continue.  Other Modula-2 compilers are currently
  210.      not supported, and attempting to debug programs compiled with them
  211.      will likely result in an error as the symbol table of the
  212.      executable is read in.
  213. *Command Rationalization*
  214.      Many GDB commands have been renamed to make them easier to remember
  215.      and use.  In particular, the subcommands of `info' and
  216.      `show'/`set' are grouped to make the former refer to the state of
  217.      your program, and the latter refer to the state of GDB itself.
  218.      *Note Renamed Commands::, for details on what commands were
  219.      renamed.
  220. *Shared Libraries*
  221.      GDB 4 can debug programs and core files that use SunOS, SVR4, or
  222.      IBM RS/6000 shared libraries.
  223. *Threads*
  224.      On some systems, GDB 4 has facilities to debug multi-thread
  225.      programs.
  226. *Reference Card*
  227.      GDB 4 has a reference card.  *Note Formatting the Documentation:
  228.      Formatting Documentation, for instructions about how to print it.
  229. File: gdb.info,  Node: Sample Session,  Next: Invocation,  Prev: New Features,  Up: Top
  230. A Sample GDB Session
  231. ********************
  232.    You can use this manual at your leisure to read all about GDB.
  233. However, a handful of commands are enough to get started using the
  234. debugger.  This chapter illustrates those commands.
  235.    One of the preliminary versions of GNU `m4' (a generic macro
  236. processor) exhibits the following bug: sometimes, when we change its
  237. quote strings from the default, the commands used to capture one macro
  238. definition within another stop working.  In the following short `m4'
  239. session, we define a macro `foo' which expands to `0000'; we then use
  240. the `m4' built-in `defn' to define `bar' as the same thing.  However,
  241. when we change the open quote string to `<QUOTE>' and the close quote
  242. string to `<UNQUOTE>', the same procedure fails to define a new synonym
  243. `baz':
  244.      $ cd gnu/m4
  245.      $ ./m4
  246.      define(foo,0000)
  247.      
  248.      foo
  249.      0000
  250.      define(bar,defn(`foo'))
  251.      
  252.      bar
  253.      0000
  254.      changequote(<QUOTE>,<UNQUOTE>)
  255.      
  256.      define(baz,defn(<QUOTE>foo<UNQUOTE>))
  257.      baz
  258.      C-d
  259.      m4: End of input: 0: fatal error: EOF in string
  260. Let us use GDB to try to see what is going on.
  261.      $ gdb m4
  262.      GDB is free software and you are welcome to distribute copies
  263.       of it under certain conditions; type "show copying" to see
  264.       the conditions.
  265.      There is absolutely no warranty for GDB; type "show warranty"
  266.       for details.
  267.      GDB 4.12, Copyright 1993 Free Software Foundation, Inc...
  268.      (gdb)
  269. GDB reads only enough symbol data to know where to find the rest when
  270. needed; as a result, the first prompt comes up very quickly.  We now
  271. tell GDB to use a narrower display width than usual, so that examples
  272. fit in this manual.
  273.      (gdb) set width 70
  274. We need to see how the `m4' built-in `changequote' works.  Having
  275. looked at the source, we know the relevant subroutine is
  276. `m4_changequote', so we set a breakpoint there with the GDB `break'
  277. command.
  278.      (gdb) break m4_changequote
  279.      Breakpoint 1 at 0x62f4: file builtin.c, line 879.
  280. Using the `run' command, we start `m4' running under GDB control; as
  281. long as control does not reach the `m4_changequote' subroutine, the
  282. program runs as usual:
  283.      (gdb) run
  284.      Starting program: /work/Editorial/gdb/gnu/m4/m4
  285.      define(foo,0000)
  286.      
  287.      foo
  288.      0000
  289. To trigger the breakpoint, we call `changequote'.  GDB suspends
  290. execution of `m4', displaying information about the context where it
  291. stops.
  292.      changequote(<QUOTE>,<UNQUOTE>)
  293.      
  294.      Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
  295.          at builtin.c:879
  296.      879         if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
  297. Now we use the command `n' (`next') to advance execution to the next
  298. line of the current function.
  299.      (gdb) n
  300.      882         set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
  301.       : nil,
  302. `set_quotes' looks like a promising subroutine.  We can go into it by
  303. using the command `s' (`step') instead of `next'.  `step' goes to the
  304. next line to be executed in *any* subroutine, so it steps into
  305. `set_quotes'.
  306.      (gdb) s
  307.      set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
  308.          at input.c:530
  309.      530         if (lquote != def_lquote)
  310. The display that shows the subroutine where `m4' is now suspended (and
  311. its arguments) is called a stack frame display.  It shows a summary of
  312. the stack.  We can use the `backtrace' command (which can also be
  313. spelled `bt'), to see where we are in the stack as a whole: the
  314. `backtrace' command displays a stack frame for each active subroutine.
  315.      (gdb) bt
  316.      #0  set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
  317.          at input.c:530
  318.      #1  0x6344 in m4_changequote (argc=3, argv=0x33c70)
  319.          at builtin.c:882
  320.      #2  0x8174 in expand_macro (sym=0x33320) at macro.c:242
  321.      #3  0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
  322.          at macro.c:71
  323.      #4  0x79dc in expand_input () at macro.c:40
  324.      #5  0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
  325. We step through a few more lines to see what happens.  The first two
  326. times, we can use `s'; the next two times we use `n' to avoid falling
  327. into the `xstrdup' subroutine.
  328.      (gdb) s
  329.      0x3b5c  532         if (rquote != def_rquote)
  330.      (gdb) s
  331.      0x3b80  535         lquote = (lq == nil || *lq == '\0') ?  \
  332.      def_lquote : xstrdup(lq);
  333.      (gdb) n
  334.      536         rquote = (rq == nil || *rq == '\0') ? def_rquote\
  335.       : xstrdup(rq);
  336.      (gdb) n
  337.      538         len_lquote = strlen(rquote);
  338. The last line displayed looks a little odd; we can examine the variables
  339. `lquote' and `rquote' to see if they are in fact the new left and right
  340. quotes we specified.  We use the command `p' (`print') to see their
  341. values.
  342.      (gdb) p lquote
  343.      $1 = 0x35d40 "<QUOTE>"
  344.      (gdb) p rquote
  345.      $2 = 0x35d50 "<UNQUOTE>"
  346. `lquote' and `rquote' are indeed the new left and right quotes.  To
  347. look at some context, we can display ten lines of source surrounding
  348. the current line with the `l' (`list') command.
  349.      (gdb) l
  350.      533             xfree(rquote);
  351.      534
  352.      535         lquote = (lq == nil || *lq == '\0') ? def_lquote\
  353.       : xstrdup (lq);
  354.      536         rquote = (rq == nil || *rq == '\0') ? def_rquote\
  355.       : xstrdup (rq);
  356.      537
  357.      538         len_lquote = strlen(rquote);
  358.      539         len_rquote = strlen(lquote);
  359.      540     }
  360.      541
  361.      542     void
  362. Let us step past the two lines that set `len_lquote' and `len_rquote',
  363. and then examine the values of those variables.
  364.      (gdb) n
  365.      539         len_rquote = strlen(lquote);
  366.      (gdb) n
  367.      540     }
  368.      (gdb) p len_lquote
  369.      $3 = 9
  370.      (gdb) p len_rquote
  371.      $4 = 7
  372. That certainly looks wrong, assuming `len_lquote' and `len_rquote' are
  373. meant to be the lengths of `lquote' and `rquote' respectively.  We can
  374. set them to better values using the `p' command, since it can print the
  375. value of any expression--and that expression can include subroutine
  376. calls and assignments.
  377.      (gdb) p len_lquote=strlen(lquote)
  378.      $5 = 7
  379.      (gdb) p len_rquote=strlen(rquote)
  380.      $6 = 9
  381. Is that enough to fix the problem of using the new quotes with the `m4'
  382. built-in `defn'?  We can allow `m4' to continue executing with the `c'
  383. (`continue') command, and then try the example that caused trouble
  384. initially:
  385.      (gdb) c
  386.      Continuing.
  387.      
  388.      define(baz,defn(<QUOTE>foo<UNQUOTE>))
  389.      
  390.      baz
  391.      0000
  392. Success!  The new quotes now work just as well as the default ones.  The
  393. problem seems to have been just the two typos defining the wrong
  394. lengths.  We allow `m4' exit by giving it an EOF as input:
  395.      C-d
  396.      Program exited normally.
  397. The message `Program exited normally.' is from GDB; it indicates `m4'
  398. has finished executing.  We can end our GDB session with the GDB `quit'
  399. command.
  400.      (gdb) quit
  401. File: gdb.info,  Node: Invocation,  Next: Commands,  Prev: Sample Session,  Up: Top
  402. Getting In and Out of GDB
  403. *************************
  404.    This chapter discusses how to start GDB, and how to get out of it.
  405. (The essentials: type `gdb' to start GDB, and type `quit' or `C-d' to
  406. exit.)
  407. * Menu:
  408. * Invoking GDB::                How to start GDB
  409. * Quitting GDB::                 How to quit GDB
  410. * Shell Commands::              How to use shell commands inside GDB
  411. File: gdb.info,  Node: Invoking GDB,  Next: Quitting GDB,  Up: Invocation
  412. Invoking GDB
  413. ============
  414.    Invoke GDB by running the program `gdb'.  Once started, GDB reads
  415. commands from the terminal until you tell it to exit.
  416.    You can also run `gdb' with a variety of arguments and options, to
  417. specify more of your debugging environment at the outset.
  418.    The command-line options described here are designed to cover a
  419. variety of situations; in some environments, some of these options may
  420. effectively be unavailable.
  421.    The most usual way to start GDB is with one argument, specifying an
  422. executable program:
  423.      gdb PROGRAM
  424. You can also start with both an executable program and a core file
  425. specified:
  426.      gdb PROGRAM CORE
  427.    You can, instead, specify a process ID as a second argument, if you
  428. want to debug a running process:
  429.      gdb PROGRAM 1234
  430. would attach GDB to process `1234' (unless you also have a file named
  431. `1234'; GDB does check for a core file first).
  432.    Taking advantage of the second command-line argument requires a
  433. fairly complete operating system; when you use GDB as a remote debugger
  434. attached to a bare board, there may not be any notion of "process", and
  435. there is often no way to get a core dump.
  436. You can further control how GDB starts up by using command-line
  437. options.  GDB itself can remind you of the options available.
  438.      gdb -help
  439. to display all available options and briefly describe their use (`gdb
  440. -h' is a shorter equivalent).
  441.    All options and command line arguments you give are processed in
  442. sequential order.  The order makes a difference when the `-x' option is
  443. used.
  444. * Menu:
  445. * File Options::                Choosing files
  446. * Mode Options::                Choosing modes
  447. File: gdb.info,  Node: File Options,  Next: Mode Options,  Up: Invoking GDB
  448. Choosing files
  449. --------------
  450.    When GDB starts, it reads any arguments other than options as
  451. specifying an executable file and core file (or process ID).  This is
  452. the same as if the arguments were specified by the `-se' and `-c'
  453. options respectively.  (GDB reads the first argument that does not have
  454. an associated option flag as equivalent to the `-se' option followed by
  455. that argument; and the second argument that does not have an associated
  456. option flag, if any, as equivalent to the `-c' option followed by that
  457. argument.)
  458.    Many options have both long and short forms; both are shown in the
  459. following list.  GDB also recognizes the long forms if you truncate
  460. them, so long as enough of the option is present to be unambiguous.
  461. (If you prefer, you can flag option arguments with `--' rather than
  462. `-', though we illustrate the more usual convention.)
  463. `-symbols FILE'
  464. `-s FILE'
  465.      Read symbol table from file FILE.
  466. `-exec FILE'
  467. `-e FILE'
  468.      Use file FILE as the executable file to execute when appropriate,
  469.      and for examining pure data in conjunction with a core dump.
  470. `-se FILE'
  471.      Read symbol table from file FILE and use it as the executable file.
  472. `-core FILE'
  473. `-c FILE'
  474.      Use file FILE as a core dump to examine.
  475. `-c NUMBER'
  476.      Connect to process ID NUMBER, as with the `attach' command (unless
  477.      there is a file in core-dump format named NUMBER, in which case
  478.      `-c' specifies that file as a core dump to read).
  479. `-command FILE'
  480. `-x FILE'
  481.      Execute GDB commands from file FILE.  *Note Command files: Command
  482.      Files.
  483. `-directory DIRECTORY'
  484. `-d DIRECTORY'
  485.      Add DIRECTORY to the path to search for source files.
  486. `-mapped'
  487.      *Warning: this option depends on operating system facilities that
  488.      are not supported on all systems.*
  489.      If memory-mapped files are available on your system through the
  490.      `mmap' system call, you can use this option to have GDB write the
  491.      symbols from your program into a reusable file in the current
  492.      directory.  If the program you are debugging is called
  493.      `/tmp/fred', the mapped symbol file is `./fred.syms'.  Future GDB
  494.      debugging sessions notice the presence of this file, and can
  495.      quickly map in symbol information from it, rather than reading the
  496.      symbol table from the executable program.
  497.      The `.syms' file is specific to the host machine where GDB is run.
  498.      It holds an exact image of the internal GDB symbol table.  It
  499.      cannot be shared across multiple host platforms.
  500. `-readnow'
  501.      Read each symbol file's entire symbol table immediately, rather
  502.      than the default, which is to read it incrementally as it is
  503.      needed.  This makes startup slower, but makes future operations
  504.      faster.
  505.    The `-mapped' and `-readnow' options are typically combined in order
  506. to build a `.syms' file that contains complete symbol information.
  507. (*Note Commands to specify files: Files, for information on `.syms'
  508. files.)  A simple GDB invocation to do nothing but build a `.syms' file
  509. for future use is:
  510.          gdb -batch -nx -mapped -readnow programname
  511. File: gdb.info,  Node: Mode Options,  Prev: File Options,  Up: Invoking GDB
  512. Choosing modes
  513. --------------
  514.    You can run GDB in various alternative modes--for example, in batch
  515. mode or quiet mode.
  516. `-nx'
  517.      Do not execute commands from any initialization files (normally
  518.      called `.gdbinit').  Normally, the commands in these files are
  519.      executed after all the command options and arguments have been
  520.      processed.  *Note Command files: Command Files.
  521. `-quiet'
  522.      "Quiet".  Do not print the introductory and copyright messages.
  523.      These messages are also suppressed in batch mode.
  524. `-batch'
  525.      Run in batch mode.  Exit with status `0' after processing all the
  526.      command files specified with `-x' (and all commands from
  527.      initialization files, if not inhibited with `-n').  Exit with
  528.      nonzero status if an error occurs in executing the GDB commands in
  529.      the command files.
  530.      Batch mode may be useful for running GDB as a filter, for example
  531.      to download and run a program on another computer; in order to
  532.      make this more useful, the message
  533.           Program exited normally.
  534.      (which is ordinarily issued whenever a program running under GDB
  535.      control terminates) is not issued when running in batch mode.
  536. `-cd DIRECTORY'
  537.      Run GDB using DIRECTORY as its working directory, instead of the
  538.      current directory.
  539. `-fullname'
  540.      Emacs sets this option when it runs GDB as a subprocess.  It tells
  541.      GDB to output the full file name and line number in a standard,
  542.      recognizable fashion each time a stack frame is displayed (which
  543.      includes each time your program stops).  This recognizable format
  544.      looks like two `\032' characters, followed by the file name, line
  545.      number and character position separated by colons, and a newline.
  546.      The Emacs-to-GDB interface program uses the two `\032' characters
  547.      as a signal to display the source code for the frame.
  548. `-b BPS'
  549.      Set the line speed (baud rate or bits per second) of any serial
  550.      interface used by GDB for remote debugging.
  551. `-tty DEVICE'
  552.      Run using DEVICE for your program's standard input and output.
  553. File: gdb.info,  Node: Quitting GDB,  Next: Shell Commands,  Prev: Invoking GDB,  Up: Invocation
  554. Quitting GDB
  555. ============
  556. `quit'
  557.      To exit GDB, use the `quit' command (abbreviated `q'), or type an
  558.      end-of-file character (usually `C-d').
  559.    An interrupt (often `C-c') does not exit from GDB, but rather
  560. terminates the action of any GDB command that is in progress and
  561. returns to GDB command level.  It is safe to type the interrupt
  562. character at any time because GDB does not allow it to take effect
  563. until a time when it is safe.
  564.    If you have been using GDB to control an attached process or device,
  565. you can release it with the `detach' command (*note Debugging an
  566. already-running process: Attach.).
  567. File: gdb.info,  Node: Shell Commands,  Prev: Quitting GDB,  Up: Invocation
  568. Shell commands
  569. ==============
  570.    If you need to execute occasional shell commands during your
  571. debugging session, there is no need to leave or suspend GDB; you can
  572. just use the `shell' command.
  573. `shell COMMAND STRING'
  574.      Invoke a the standard shell to execute COMMAND STRING.  If it
  575.      exists, the environment variable `SHELL' determines which shell to
  576.      run.  Otherwise GDB uses `/bin/sh'.
  577.    The utility `make' is often needed in development environments.  You
  578. do not have to use the `shell' command for this purpose in GDB:
  579. `make MAKE-ARGS'
  580.      Execute the `make' program with the specified arguments.  This is
  581.      equivalent to `shell make MAKE-ARGS'.
  582. File: gdb.info,  Node: Commands,  Next: Running,  Prev: Invocation,  Up: Top
  583. GDB Commands
  584. ************
  585.    You can abbreviate a GDB command to the first few letters of the
  586. command name, if that abbreviation is unambiguous; and you can repeat
  587. certain GDB commands by typing just RET.  You can also use the TAB key
  588. to get GDB to fill out the rest of a word in a command (or to show you
  589. the alternatives available, if there is more than one possibility).
  590. * Menu:
  591. * Command Syntax::              How to give commands to GDB
  592. * Completion::                  Command completion
  593. * Help::                        How to ask GDB for help
  594. File: gdb.info,  Node: Command Syntax,  Next: Completion,  Up: Commands
  595. Command syntax
  596. ==============
  597.    A GDB command is a single line of input.  There is no limit on how
  598. long it can be.  It starts with a command name, which is followed by
  599. arguments whose meaning depends on the command name.  For example, the
  600. command `step' accepts an argument which is the number of times to
  601. step, as in `step 5'.  You can also use the `step' command with no
  602. arguments.  Some command names do not allow any arguments.
  603.    GDB command names may always be truncated if that abbreviation is
  604. unambiguous.  Other possible command abbreviations are listed in the
  605. documentation for individual commands.  In some cases, even ambiguous
  606. abbreviations are allowed; for example, `s' is specially defined as
  607. equivalent to `step' even though there are other commands whose names
  608. start with `s'.  You can test abbreviations by using them as arguments
  609. to the `help' command.
  610.    A blank line as input to GDB (typing just RET) means to repeat the
  611. previous command. Certain commands (for example, `run') will not repeat
  612. this way; these are commands whose unintentional repetition might cause
  613. trouble and which you are unlikely to want to repeat.
  614.    The `list' and `x' commands, when you repeat them with RET,
  615. construct new arguments rather than repeating exactly as typed.  This
  616. permits easy scanning of source or memory.
  617.    GDB can also use RET in another way: to partition lengthy output, in
  618. a way similar to the common utility `more' (*note Screen size: Screen
  619. Size.).  Since it is easy to press one RET too many in this situation,
  620. GDB disables command repetition after any command that generates this
  621. sort of display.
  622.    Any text from a `#' to the end of the line is a comment; it does
  623. nothing.  This is useful mainly in command files (*note Command files:
  624. Command Files.).
  625. File: gdb.info,  Node: Completion,  Next: Help,  Prev: Command Syntax,  Up: Commands
  626. Command completion
  627. ==================
  628.    GDB can fill in the rest of a word in a command for you, if there is
  629. only one possibility; it can also show you what the valid possibilities
  630. are for the next word in a command, at any time.  This works for GDB
  631. commands, GDB subcommands, and the names of symbols in your program.
  632.    Press the TAB key whenever you want GDB to fill out the rest of a
  633. word.  If there is only one possibility, GDB fills in the word, and
  634. waits for you to finish the command (or press RET to enter it).  For
  635. example, if you type
  636.      (gdb) info bre TAB
  637. GDB fills in the rest of the word `breakpoints', since that is the only
  638. `info' subcommand beginning with `bre':
  639.      (gdb) info breakpoints
  640. You can either press RET at this point, to run the `info breakpoints'
  641. command, or backspace and enter something else, if `breakpoints' does
  642. not look like the command you expected.  (If you were sure you wanted
  643. `info breakpoints' in the first place, you might as well just type RET
  644. immediately after `info bre', to exploit command abbreviations rather
  645. than command completion).
  646.    If there is more than one possibility for the next word when you
  647. press TAB, GDB sounds a bell.  You can either supply more characters
  648. and try again, or just press TAB a second time; GDB displays all the
  649. possible completions for that word.  For example, you might want to set
  650. a breakpoint on a subroutine whose name begins with `make_', but when
  651. you type `b make_TAB' GDB just sounds the bell.  Typing TAB again
  652. displays all the function names in your program that begin with those
  653. characters, for example:
  654.      (gdb) b make_ TAB
  655. GDB sounds bell; press TAB again, to see:
  656.      make_a_section_from_file     make_environ
  657.      make_abs_section             make_function_type
  658.      make_blockvector             make_pointer_type
  659.      make_cleanup                 make_reference_type
  660.      make_command                 make_symbol_completion_list
  661.      (gdb) b make_
  662. After displaying the available possibilities, GDB copies your partial
  663. input (`b make_' in the example) so you can finish the command.
  664.    If you just want to see the list of alternatives in the first place,
  665. you can press `M-?' rather than pressing TAB twice. `M-?' means `META
  666. ?'.  You can type this either by holding down a key designated as the
  667. META shift on your keyboard (if there is one) while typing `?', or as
  668. ESC followed by `?'.
  669.    Sometimes the string you need, while logically a "word", may contain
  670. parentheses or other characters that GDB normally excludes from its
  671. notion of a word.  To permit word completion to work in this situation,
  672. you may enclose words in `'' (single quote marks) in GDB commands.
  673.    The most likely situation where you might need this is in typing the
  674. name of a C++ function.  This is because C++ allows function overloading
  675. (multiple definitions of the same function, distinguished by argument
  676. type).  For example, when you want to set a breakpoint you may need to
  677. distinguish whether you mean the version of `name' that takes an `int'
  678. parameter, `name(int)', or the version that takes a `float' parameter,
  679. `name(float)'.  To use the word-completion facilities in this
  680. situation, type a single quote `'' at the beginning of the function
  681. name.  This alerts GDB that it may need to consider more information
  682. than usual when you press TAB or `M-?' to request word completion:
  683.      (gdb) b 'bubble( M-?
  684.      bubble(double,double)    bubble(int,int)
  685.      (gdb) b 'bubble(
  686.    In some cases, GDB can tell that completing a name requires using
  687. quotes.  When this happens, GDB inserts the quote for you (while
  688. completing as much as it can) if you do not type the quote in the first
  689. place:
  690.      (gdb) b bub TAB
  691. GDB alters your input line to the following, and rings a bell:
  692.      (gdb) b 'bubble(
  693. In general, GDB can tell that a quote is needed (and inserts it) if you
  694. have not yet started typing the argument list when you ask for
  695. completion on an overloaded symbol.
  696. File: gdb.info,  Node: Help,  Prev: Completion,  Up: Commands
  697. Getting help
  698. ============
  699.    You can always ask GDB itself for information on its commands, using
  700. the command `help'.
  701. `help'
  702.      You can use `help' (abbreviated `h') with no arguments to display
  703.      a short list of named classes of commands:
  704.           (gdb) help
  705.           List of classes of commands:
  706.           
  707.           running -- Running the program
  708.           stack -- Examining the stack
  709.           data -- Examining data
  710.           breakpoints -- Making program stop at certain points
  711.           files -- Specifying and examining files
  712.           status -- Status inquiries
  713.           support -- Support facilities
  714.           user-defined -- User-defined commands
  715.           aliases -- Aliases of other commands
  716.           obscure -- Obscure features
  717.           
  718.           Type "help" followed by a class name for a list of
  719.           commands in that class.
  720.           Type "help" followed by command name for full
  721.           documentation.
  722.           Command name abbreviations are allowed if unambiguous.
  723.           (gdb)
  724. `help CLASS'
  725.      Using one of the general help classes as an argument, you can get a
  726.      list of the individual commands in that class.  For example, here
  727.      is the help display for the class `status':
  728.           (gdb) help status
  729.           Status inquiries.
  730.           
  731.           List of commands:
  732.           
  733.           show -- Generic command for showing things set
  734.            with "set"
  735.           info -- Generic command for printing status
  736.           
  737.           Type "help" followed by command name for full
  738.           documentation.
  739.           Command name abbreviations are allowed if unambiguous.
  740.           (gdb)
  741. `help COMMAND'
  742.      With a command name as `help' argument, GDB displays a short
  743.      paragraph on how to use that command.
  744.    In addition to `help', you can use the GDB commands `info' and
  745. `show' to inquire about the state of your program, or the state of GDB
  746. itself.  Each command supports many topics of inquiry; this manual
  747. introduces each of them in the appropriate context.  The listings under
  748. `info' and under `show' in the Index point to all the sub-commands.
  749. *Note Index::.
  750. `info'
  751.      This command (abbreviated `i') is for describing the state of your
  752.      program.  For example, you can list the arguments given to your
  753.      program with `info args', list the registers currently in use with
  754.      `info registers', or list the breakpoints you have set with `info
  755.      breakpoints'.  You can get a complete list of the `info'
  756.      sub-commands with `help info'.
  757. `show'
  758.      In contrast, `show' is for describing the state of GDB itself.
  759.      You can change most of the things you can `show', by using the
  760.      related command `set'; for example, you can control what number
  761.      system is used for displays with `set radix', or simply inquire
  762.      which is currently in use with `show radix'.
  763.      To display all the settable parameters and their current values,
  764.      you can use `show' with no arguments; you may also use `info set'.
  765.      Both commands produce the same display.
  766.    Here are three miscellaneous `show' subcommands, all of which are
  767. exceptional in lacking corresponding `set' commands:
  768. `show version'
  769.      Show what version of GDB is running.  You should include this
  770.      information in GDB bug-reports.  If multiple versions of GDB are in
  771.      use at your site, you may occasionally want to determine which
  772.      version of GDB you are running; as GDB evolves, new commands are
  773.      introduced, and old ones may wither away.  The version number is
  774.      also announced when you start GDB.
  775. `show copying'
  776.      Display information about permission for copying GDB.
  777. `show warranty'
  778.      Display the GNU "NO WARRANTY" statement.
  779. File: gdb.info,  Node: Running,  Next: Stopping,  Prev: Commands,  Up: Top
  780. Running Programs Under GDB
  781. **************************
  782.    When you run a program under GDB, you must first generate debugging
  783. information when you compile it.  You may start it with its arguments,
  784. if any, in an environment of your choice.  You may redirect your
  785. program's input and output, debug an already running process, or kill a
  786. child process.
  787. * Menu:
  788. * Compilation::                 Compiling for debugging
  789. * Starting::                    Starting your program
  790. * Arguments::                   Your program's arguments
  791. * Environment::                 Your program's environment
  792. * Working Directory::           Your program's working directory
  793. * Input/Output::                Your program's input and output
  794. * Attach::                      Debugging an already-running process
  795. * Kill Process::                Killing the child process
  796. * Process Information::         Additional process information
  797. * Threads::            Debugging programs with multiple threads
  798. File: gdb.info,  Node: Compilation,  Next: Starting,  Up: Running
  799. Compiling for debugging
  800. =======================
  801.    In order to debug a program effectively, you need to generate
  802. debugging information when you compile it.  This debugging information
  803. is stored in the object file; it describes the data type of each
  804. variable or function and the correspondence between source line numbers
  805. and addresses in the executable code.
  806.    To request debugging information, specify the `-g' option when you
  807. run the compiler.
  808.    Many C compilers are unable to handle the `-g' and `-O' options
  809. together.  Using those compilers, you cannot generate optimized
  810. executables containing debugging information.
  811.    GCC, the GNU C compiler, supports `-g' with or without `-O', making
  812. it possible to debug optimized code.  We recommend that you *always*
  813. use `-g' whenever you compile a program.  You may think your program is
  814. correct, but there is no sense in pushing your luck.
  815.    When you debug a program compiled with `-g -O', remember that the
  816. optimizer is rearranging your code; the debugger shows you what is
  817. really there.  Do not be too surprised when the execution path does not
  818. exactly match your source file!  An extreme example: if you define a
  819. variable, but never use it, GDB never sees that variable--because the
  820. compiler optimizes it out of existence.
  821.    Some things do not work as well with `-g -O' as with just `-g',
  822. particularly on machines with instruction scheduling.  If in doubt,
  823. recompile with `-g' alone, and if this fixes the problem, please report
  824. it as a bug (including a test case!).
  825.    Older versions of the GNU C compiler permitted a variant option
  826. `-gg' for debugging information.  GDB no longer supports this format;
  827. if your GNU C compiler has this option, do not use it.
  828. File: gdb.info,  Node: Starting,  Next: Arguments,  Prev: Compilation,  Up: Running
  829. Starting your program
  830. =====================
  831. `run'
  832.      Use the `run' command to start your program under GDB.  You must
  833.      first specify the program name (except on VxWorks) with an
  834.      argument to GDB (*note Getting In and Out of GDB: Invocation.), or
  835.      by using the `file' or `exec-file' command (*note Commands to
  836.      specify files: Files.).
  837.    If you are running your program in an execution environment that
  838. supports processes, `run' creates an inferior process and makes that
  839. process run your program.  (In environments without processes, `run'
  840. jumps to the start of your program.)
  841.    The execution of a program is affected by certain information it
  842. receives from its superior.  GDB provides ways to specify this
  843. information, which you must do *before* starting your program.  (You
  844. can change it after starting your program, but such changes only affect
  845. your program the next time you start it.)  This information may be
  846. divided into four categories:
  847. The *arguments.*
  848.      Specify the arguments to give your program as the arguments of the
  849.      `run' command.  If a shell is available on your target, the shell
  850.      is used to pass the arguments, so that you may use normal
  851.      conventions (such as wildcard expansion or variable substitution)
  852.      in describing the arguments.  In Unix systems, you can control
  853.      which shell is used with the `SHELL' environment variable. *Note
  854.      Your program's arguments: Arguments.
  855. The *environment.*
  856.      Your program normally inherits its environment from GDB, but you
  857.      can use the GDB commands `set environment' and `unset environment'
  858.      to change parts of the environment that affect your program.
  859.      *Note Your program's environment: Environment.
  860. The *working directory.*
  861.      Your program inherits its working directory from GDB.  You can set
  862.      the GDB working directory with the `cd' command in GDB.  *Note
  863.      Your program's working directory: Working Directory.
  864. The *standard input and output.*
  865.      Your program normally uses the same device for standard input and
  866.      standard output as GDB is using.  You can redirect input and output
  867.      in the `run' command line, or you can use the `tty' command to set
  868.      a different device for your program.  *Note Your program's input
  869.      and output: Input/Output.
  870.      *Warning:* While input and output redirection work, you cannot use
  871.      pipes to pass the output of the program you are debugging to
  872.      another program; if you attempt this, GDB is likely to wind up
  873.      debugging the wrong program.
  874.    When you issue the `run' command, your program begins to execute
  875. immediately.  *Note Stopping and continuing: Stopping, for discussion
  876. of how to arrange for your program to stop.  Once your program has
  877. stopped, you may call functions in your program, using the `print' or
  878. `call' commands.  *Note Examining Data: Data.
  879.    If the modification time of your symbol file has changed since the
  880. last time GDB read its symbols, GDB discards its symbol table, and
  881. reads it again.  When it does this, GDB tries to retain your current
  882. breakpoints.
  883. File: gdb.info,  Node: Arguments,  Next: Environment,  Prev: Starting,  Up: Running
  884. Your program's arguments
  885. ========================
  886.    The arguments to your program can be specified by the arguments of
  887. the `run' command.  They are passed to a shell, which expands wildcard
  888. characters and performs redirection of I/O, and thence to your program.
  889. Your `SHELL' environment variable (if it exists) specifies what shell
  890. GDB if you do not define `SHELL', GDB uses `/bin/sh'.
  891.    `run' with no arguments uses the same arguments used by the previous
  892. `run', or those set by the `set args' command.
  893. `set args'
  894.      Specify the arguments to be used the next time your program is
  895.      run.  If `set args' has no arguments, `run' executes your program
  896.      with no arguments.  Once you have run your program with arguments,
  897.      using `set args' before the next `run' is the only way to run it
  898.      again without arguments.
  899. `show args'
  900.      Show the arguments to give your program when it is started.
  901. File: gdb.info,  Node: Environment,  Next: Working Directory,  Prev: Arguments,  Up: Running
  902. Your program's environment
  903. ==========================
  904.    The "environment" consists of a set of environment variables and
  905. their values.  Environment variables conventionally record such things
  906. as your user name, your home directory, your terminal type, and your
  907. search path for programs to run.  Usually you set up environment
  908. variables with the shell and they are inherited by all the other
  909. programs you run.  When debugging, it can be useful to try running your
  910. program with a modified environment without having to start GDB over
  911. again.
  912. `path DIRECTORY'
  913.      Add DIRECTORY to the front of the `PATH' environment variable (the
  914.      search path for executables), for both GDB and your program.  You
  915.      may specify several directory names, separated by `:' or
  916.      whitespace.  If DIRECTORY is already in the path, it is moved to
  917.      the front, so it is searched sooner.
  918.      You can use the string `$cwd' to refer to whatever is the current
  919.      working directory at the time GDB searches the path.  If you use
  920.      `.' instead, it refers to the directory where you executed the
  921.      `path' command.  GDB replaces `.' in the DIRECTORY argument (with
  922.      the current path) before adding DIRECTORY to the search path.
  923. `show paths'
  924.      Display the list of search paths for executables (the `PATH'
  925.      environment variable).
  926. `show environment [VARNAME]'
  927.      Print the value of environment variable VARNAME to be given to
  928.      your program when it starts.  If you do not supply VARNAME, print
  929.      the names and values of all environment variables to be given to
  930.      your program.  You can abbreviate `environment' as `env'.
  931. `set environment VARNAME [=] VALUE'
  932.      Set environment variable VARNAME to VALUE.  The value changes for
  933.      your program only, not for GDB itself.  VALUE may be any string;
  934.      the values of environment variables are just strings, and any
  935.      interpretation is supplied by your program itself.  The VALUE
  936.      parameter is optional; if it is eliminated, the variable is set to
  937.      a null value.
  938.      For example, this command:
  939.           set env USER = foo
  940.      tells a Unix program, when subsequently run, that its user is named
  941.      `foo'.  (The spaces around `=' are used for clarity here; they are
  942.      not actually required.)
  943. `unset environment VARNAME'
  944.      Remove variable VARNAME from the environment to be passed to your
  945.      program.  This is different from `set env VARNAME ='; `unset
  946.      environment' removes the variable from the environment, rather
  947.      than assigning it an empty value.
  948.    *Warning:* GDB runs your program using the shell indicated by your
  949. `SHELL' environment variable if it exists (or `/bin/sh' if not).  If
  950. your `SHELL' variable names a shell that runs an initialization
  951. file--such as `.cshrc' for C-shell, or `.bashrc' for BASH--any
  952. variables you set in that file affect your program.  You may wish to
  953. move setting of environment variables to files that are only run when
  954. you sign on, such as `.login' or `.profile'.
  955. File: gdb.info,  Node: Working Directory,  Next: Input/Output,  Prev: Environment,  Up: Running
  956. Your program's working directory
  957. ================================
  958.    Each time you start your program with `run', it inherits its working
  959. directory from the current working directory of GDB.  The GDB working
  960. directory is initially whatever it inherited from its parent process
  961. (typically the shell), but you can specify a new working directory in
  962. GDB with the `cd' command.
  963.    The GDB working directory also serves as a default for the commands
  964. that specify files for GDB to operate on.  *Note Commands to specify
  965. files: Files.
  966. `cd DIRECTORY'
  967.      Set the GDB working directory to DIRECTORY.
  968. `pwd'
  969.      Print the GDB working directory.
  970.